import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {
    private FlowBean outK = new FlowBean();
    private Text outV = new Text();
    //        手机      上行流量 下行流量 总流量
    // 入数：17320092010  188    200    388
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, FlowBean, Text>.Context context) throws IOException, InterruptedException {

        System.out.println("------------调用map函数----------------");
        System.out.println("参数：key = " + key.toString() + " value = " + value.toString() );
        // 获取一行
        String string = value.toString();

        // 切割
        String[] strings = string.split(" ");

        // 封装 FlowBean
        outV.set(strings[0]);
        outK.setUpFlow(Long.parseLong(strings[1]));
        outK.setDownFlow(Long.parseLong(strings[2]));
        outK.setSumFlow();

        // 写出 key为手机号码对应流量信息的对象，value为手机号码
        context.write(outK, outV);


    }
}
